/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DivisionPanel.java
 *
 * Created on 1/09/2011, 08:48:13 PM
 */
package boundary.panel;

import control.Calculadora;
import control.OperacionesBasicas;

/**
 *
 * @author Silex RPR
 */
public class DivisionPanel extends javax.swing.JPanel {
    private OperacionesBasicas operaciones;
    /** Creates new form DivisionPanel */
    public DivisionPanel(OperacionesBasicas ob) {
        this.operaciones = ob;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        numberATF = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        numberBTF = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        labelResultado = new javax.swing.JLabel();
        calculateB = new javax.swing.JButton();
        backB = new javax.swing.JButton();
        labelError = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(420, 248));

        jLabel1.setText("/");

        jLabel2.setText("=");

        labelResultado.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        calculateB.setText("Calculate");
        calculateB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calculateBActionPerformed(evt);
            }
        });

        backB.setText("Back");
        backB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                backBActionPerformed(evt);
            }
        });

        labelError.setFont(new java.awt.Font("Tahoma", 1, 11));

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel3.setText("Division Operation ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelError, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(calculateB)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(backB)))
                .addGap(17, 17, 17))
            .addGroup(layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(numberATF, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(numberBTF, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel2)
                        .addGap(12, 12, 12)
                        .addComponent(labelResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addComponent(jLabel3)
                .addGap(58, 58, 58)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numberATF, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(labelResultado, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(numberBTF, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(52, 52, 52)
                .addComponent(labelError, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(calculateB)
                    .addComponent(backB))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void calculateBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calculateBActionPerformed
        String parseResult = this.operaciones.parseData(numberATF.getText(),numberBTF.getText());
        if (parseResult.equals("")){
            float result = this.operaciones.Division(Float.valueOf(numberATF.getText()),
                    Float.valueOf(numberBTF.getText()));
            labelResultado.setText(String.valueOf(result));
            
        } else {
            labelError.setText(parseResult);
        }
}//GEN-LAST:event_calculateBActionPerformed

private void backBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backBActionPerformed
Calculadora.getApplication().getMainFrame().getPanelMenu().removeAll(); 
    Calculadora.getApplication().getMainFrame().getPanelMenu().setVisible(false);
    Calculadora.getApplication().getMainFrame().reInit();
}//GEN-LAST:event_backBActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton backB;
    private javax.swing.JButton calculateB;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel labelError;
    private javax.swing.JLabel labelResultado;
    private javax.swing.JTextField numberATF;
    private javax.swing.JTextField numberBTF;
    // End of variables declaration//GEN-END:variables
}
